/*-
 * Copyright (c) 2007 Martin Akesson <makesson@gmail.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 */

#ifndef __CDTEXT_H
#define __CDTEXT_H

/* ID1 - CD-Text pack type
 *   7   6   5   4   3   2   1   0
 * +---+---+---+---+---+---+---+---+
 * | x | x | x | x | x | x | x | x |
 * +---+---+---+---+---+---+---+---+
 *
 * (x)
 * 80h - Album title (ID2=00h) / Song name (ID2=01h...63h)
 * 81h - Performer name
 * 82h - Song writer name
 * 83h - Composer name
 * 84h - Arranger name
 * 85h - Message from artist / content provider
 * 86h - Disc ID
 * 87h - Search keyword / Genre
 * 88h - TOC
 * 89h - 2nd TOC
 * 8ah - Reserved
 * 8bh - Reserved
 * 8ch - Reserved
 * 8dh - Reserved for content provider
 * 8eh - UPC/EAN code of the album & ISRC code of each track
 * 8fh - Size information of the block
 * Range: 0 - 255
 */

/* ID2 - Track number
 *   7   6   5   4   3   2   1   0
 * +---+---+---+---+---+---+---+---+
 * | 0 | x | x | x | x | x | x | x |
 * +---+---+---+---+---+---+---+---+
 *
 * (x)
 * Specifies the track this pack belongs to.  Track 0 specifies
 * the album itself.
 * Range: 0 - 99
 *
 * Bit7 is reserved.
 */

/* ID3 - Block sequential number
 *   7   6   5   4   3   2   1   0
 * +---+---+---+---+---+---+---+---+
 * | x | x | x | x | x | x | x | x |
 * +---+---+---+---+---+---+---+---+
 *
 * (x)
 * The sequential number of rhe pack is increased incrementally
 * for each pack.
 * Range: 0 - 255
 */

/* ID4 - Block number and character position
 *   7   6   5   4   3   2   1   0
 * +---+---+---+---+---+---+---+---+
 * | x | y | y | y | z | z | z | z |
 * +---+---+---+---+---+---+---+---+
 *
 * (x)
 * Double byte character code (DBCC) indicator.  If this bit is
 * set the text data is in double byte character code.
 *
 * (y)
 * Block number that this pack belongs to
 *
 * (z)
 * Character position indicator specifies the number of characters
 * in the text data that belongs to the previous pack.  The character
 * position starts from 0 to 15.  A index of 15 indicates that the
 * first character belongs to the one before the previous pack.
 * If DBCC is set a set of 2 bytes in text data is counted as one.
 */

enum { CDTX_ALBUM_TITLE = 0x80, CDTX_SONG_TITLE = 0x80, CDTX_PERFORMER_NAME,
    CDTX_SONGWRITER_NAME, CDTX_COMPOSER_NAME, CDTX_ARRANGER_NAME,
    CDTX_MESSAGE, CDTX_DISC_ID, CDTX_GENRE, CDTX_TOC, CDTX_TOC2,
    CDTX_UPC_EAN_ISRC = 0x8e, CDTX_BLOCK_INFO };

typedef struct
{
    uint8_t  id1; // Pack type
    uint8_t  id2; // Track number
    uint8_t  id3; // Block seq. number
    uint8_t  id4; // Block number & character position
    char     text[12];
    uint16_t crc;   // 16bit CRC-CCITT
} __attribute__((__packed__)) cdtext_pack_t;

#endif
